﻿#include "processellipse.h"
#include <QPainter>
#include <QtDebug>
ProcessEllipse::ProcessEllipse(QWidget* parent):QWidget(parent)
  ,m_CenterPoint(this->rect().center()),m_dbNum(0),m_TextColor(Qt::white)
  ,m_OuterRingColor(Qt::red),m_InnerRingColor(QColor("#E0E0E0")),m_dbStartAngel(0)
  ,m_ValueColor(Qt::yellow)
{
    this->setPalette(QPalette(QColor(255, 255, 255)));
}

void ProcessEllipse::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.setBrush(QBrush(m_OuterRingColor));
    painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    painter.drawEllipse(m_CenterPoint, this->width()*0.3, this->width()*0.3);
    drawValue(painter);
    painter.setBrush(QBrush(m_InnerRingColor));
    painter.drawEllipse(m_CenterPoint, this->width()*0.15, this->width()*0.15);
    drawText(painter);
}


void ProcessEllipse::drawText(QPainter &painter)
{
    painter.setPen(m_TextColor);
    QFont font;
    font.setPixelSize(53);
    painter.setFont(font);
    QTextOption option;
    option.setAlignment(Qt::AlignCenter);
    painter.drawText(QRectF(0,0,this->width(),this->height()),QString("%1 %").arg(m_dbNum),option);
}

void ProcessEllipse::drawValue(QPainter &painter)
{
    QConicalGradient conical_gradient(m_CenterPoint,-m_dbStartAngel+90);
    conical_gradient.setColorAt(0.1, m_ValueColor);
    conical_gradient.setColorAt(0.5, QColor(255, 255, 255, 0));
    painter.setBrush(conical_gradient);
    painter.drawEllipse(m_CenterPoint, this->width()*0.3, this->width()*0.3);
}

void ProcessEllipse::resizeEvent(QResizeEvent *event)
{
    m_CenterPoint=QPointF(this->rect().center());
    update();
}

QColor ProcessEllipse::getValueColor() const
{
    return m_ValueColor;
}

void ProcessEllipse::setValueColor(const QColor &ValueColor)
{
    m_ValueColor = ValueColor;
    update();
}

QColor ProcessEllipse::getInnerRingColor() const
{
    return m_InnerRingColor;
}

void ProcessEllipse::setInnerRingColor(const QColor &InnerRingColor)
{
    m_InnerRingColor = InnerRingColor;
}

QColor ProcessEllipse::getOuterRing() const
{
    return m_OuterRingColor;
}

void ProcessEllipse::setOuterRing(const QColor &OuterRing)
{
    m_OuterRingColor = OuterRing;
}

QColor ProcessEllipse::getTextColor() const
{
    return m_TextColor;
}

void ProcessEllipse::setTextColor(const QColor &TextColor)
{
    m_TextColor = TextColor;
    update();
}

int ProcessEllipse::getNum() const
{
    return m_dbNum;
}

void ProcessEllipse::setNum(int iNum)
{
    m_dbStartAngel = iNum*3.6;
    m_dbNum = iNum;
    update();
}
